import { StrUtil } from '../util/StrUtil'

/**
 * FileTool
 * @author 冰凝
 * @date 2022-09-19 10:03:15
 **/
export class FileTool {

    /**
     * 获取文件扩展名
     */
    public static getExpandedName(fileName: string) {
        if (StrUtil.isEmpty(fileName)) {
            return StrUtil.EMPTY
        }
        return fileName.substring(fileName.indexOf(StrUtil.DO))
    }

    /**
     * 指定 size < sizeTarget
     * @param {number} size 待判断字节数
     * @param {number} sizeTarget 目标大小
     * @param {FileSizeEnum} e sizeTarget 单位
     * @return {boolean} size < sizeTarget * e
     */
    public static lessThan(size: number, sizeTarget: number, e: FileSizeEnum): boolean {
        return size < sizeTarget * e
    }
}

/**
 * @see StorageUnit
 */
export enum FileSizeEnum {
    KB = 1 << 10,
    MB = KB << 10,
    GB = MB << 10,
    TB = GB << 10,
}
